﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using ZhangLogSysV1d0;

namespace TmU220PrintHelperV2d0.Entity
{
    /// <summary>
    /// 打印日志
    /// </summary>
    [XmlRoot("打印日志")]
    [Serializable]
    public class PrintLogV2d0
    {
        [XmlAttribute("打印服务器名称")]
        public string ServerName { get; set; }
        [XmlAttribute("日志年")]
        public int LogYear { get; set; }
        [XmlAttribute("日志月")]
        public int LogMonth { get; set; }
        [XmlAttribute("日志日")]
        public int LogDay { get; set; }
        [XmlArray("日志项集"), XmlArrayItem("日志项")]
        public List<PrintLogItemV2d0> PrintLogItemList { get; set; }
        public PrintLogV2d0()
        {
            ServerName = "DevelopPc";
            LogYear = DateTime.Now.Year;
            LogMonth = DateTime.Now.Month;
            LogDay = DateTime.Now.Day;
            PrintLogItemList = new List<PrintLogItemV2d0>();
        }  
        public PrintLogV2d0(string serverName,int logYear,int logMonth,int logDay,List<PrintLogItemV2d0> printLogItemList)
        {
            ServerName = serverName;
            LogYear = logYear;
            LogMonth = logMonth;
            LogDay = logDay;
            PrintLogItemList = printLogItemList; 
        }

    }
    /// <summary>
    /// 打印日志项
    /// </summary>
    [XmlRoot("打印日志项")]
    [Serializable]
    public class PrintLogItemV2d0
    {
        [XmlElement(ElementName = "打印时间", Type = typeof(DateTime))]
        public DateTime PrintAchievedTime { get; set; }
        [XmlElement("打印机名称")]
        public string PrinterName { get; set; }
        [XmlElement("用户名")]
        public string UserName { get; set; }
        [XmlElement("台号")]
        public string TableNo { get; set; }
        [XmlElement("打印序号")]
        public string PrintNo { get; set; }
        [XmlElement("打印表单行数")]
        public int LineCount { get; set; }
        public PrintLogItemV2d0()
        {
            PrintAchievedTime = DateTime.Now;
            PrinterName = "192.168.3.99";
            UserName = "Admin";
            TableNo = "001";
            PrintNo = "001";
            LineCount = 0;
        }
        public PrintLogItemV2d0(DateTime printAchievedTime,string printerName,string userName,string tableNo,string printNo,int lineCount)
        {
            PrintAchievedTime = printAchievedTime;
            PrinterName = printerName;
            UserName = userName;
            TableNo = tableNo;
            PrintNo = printNo;
            LineCount = LineCount;
        }
        public PrintLogItemV2d0(PrintTaskV2d0 printTask)
        {
            PrintAchievedTime = DateTime.Now;
            PrinterName = printTask.DataOfPrintTask.act_printer;
            UserName = printTask.DataOfPrintTask.adduser;
            TableNo = printTask.DataOfPrintTask.tableno;
            PrintNo = printTask.DataOfPrintTask.print_no.HasValue? printTask.DataOfPrintTask.print_no.Value.ToString("D3"):"";
            LineCount = printTask.PrintTaskItemList.Count;
        }
    }
}
